package action.listener;

import gui.Frame;
import gui.View;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JOptionPane;

import undoredo.AbstractCommand;
import undoredo.EditVertexCommand;

public class EditVertexListener implements MouseListener
{
   private View view;
   private int x, y;

   public EditVertexListener(View view)
   {
      super();
      this.view = view;
   }

   @Override
   public void mouseClicked(MouseEvent e)
   {
      // TODO Auto-generated method stub
   }

   @Override
   public void mouseEntered(MouseEvent e)
   {
      // TODO Auto-generated method stub

   }

   @Override
   public void mouseExited(MouseEvent e)
   {
      // TODO Auto-generated method stub

   }

   @Override
   public void mousePressed(MouseEvent e)
   {
      // TODO Auto-generated method stub
      x = e.getX();
      y = e.getY();
      int i = view.isVertex(x, y);

      if (i != -1)
      {
         String name = JOptionPane.showInputDialog("Enter the new Name");
         if (name != null && name.isEmpty() == false)
         {
            //            view.getVertices().get(i).setName(name);
            AbstractCommand command = new EditVertexCommand(view.getVertices().get(i), name);
            command.execute();

            Frame.addCommandToStack(command);
            Frame.setUndoRedoVisible();

            view.repaint();
         }
      }


   }

   @Override
   public void mouseReleased(MouseEvent e)
   {
      // TODO Auto-generated method stub

   }

}
